package sysUtil

import model.LayTableCols
import sysAuth.SysOperations
import sysAuth.SysUsers

/**
 * Created by Administrator on 2018-05-21.
 */
class PageUtil {



    /**
     * 根据 SQL查询结果获取字段List
     * @param result
     * @return
     */
    public static getColsByResult(List<Map> result){
        def keys = []
        if(result && result.size() !=0){
            def data = result.get(0)
            keys = data.keySet().toList()
        }
        return keys
    }

    /**
     * 生成Layui Table Cols 模型
     * @param result
     * @return
     */
    public static getLayUiColsByResult(List result){

        def cols = getColsByResult(result)
        def data = []
        if(cols){
            cols.each{
                LayTableCols layTableCols = LayTableCols.newInstance()
                layTableCols.setField(it)
                layTableCols.setTitle(it)
                data.add(layTableCols.toMap())
            }
        }
        return data
    }

    /**
     * <button class="layui-btn layui-btn-sm layui-btn-normal"><i class="layui-icon layui-icon-face-smile"></i> 删除</button>
     * @param list
     */
    public static toolBarHtml(List list){
        StringBuffer sb = new StringBuffer("<div class='layui-btn-group'>")
        list.each {
            sb.append("<button class='layui-btn ${it.STYLE?:"layui-btn-sm"}' lay-event='${it.OPERATE_NO}' _type='${it.TYPE?:""}' _action='${it.ACTION?:""}' ><i class='layui-icon ${it.ICON}'></i>${it.OPERATE_NAME}</button>")
        }
        sb.append("</div>")
    }

    /**
     *  //<input type='checkbox' name='like[read]' title='阅读' checked>
     * @param list
     * @return
     */
    static roleCheckboxHtml(List list){
        StringBuffer sb = new StringBuffer("")
        list.each {
            sb.append("<input type='checkbox' lay-filter='roleId' name='roleId' value='${it?.ID}' title='${it?.ROLE_NAME}' ${it?.ID==it?.ROLE_ID ?"checked":""}>")
        }
        return sb
    }
}
